package com.lemei.cn.myokhttpbeen.adpter;

import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;

import com.lemei.cn.myokhttpbeen.viewholder.BeasicViewHolder;

import java.util.ArrayList;
import java.util.List;

/**
 * Created by 赵航 on 2017/6/7.
 */

public abstract class MyBesicAdapter<T> extends BaseAdapter {
    private List<T> mShowItems = new ArrayList<>();

    public MyBesicAdapter(List<T> showItems) {
        mShowItems = showItems;
    }

    @Override
    public int getCount() {
        return mShowItems == null ? 0 : mShowItems.size();
    }

    @Override
    public Object getItem(int position) {
        return mShowItems.get(position);
    }

    @Override
    public long getItemId(int position) {
        return position;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
       // ViewHolder holder;
        BeasicViewHolder holder;

        if (convertView == null) {

            holder = getViewHolder();

        } else {
            holder = (BeasicViewHolder) convertView.getTag();
        }
        //赋值
        holder.bindView(mShowItems.get(position));

        //上面的viewholder为null
        //因此下面的viewholder也是null；
        //return convertView;
        return holder.getView();
    }


    public abstract BeasicViewHolder getViewHolder();
}
